package com.gxa.dao.impl;

import com.gxa.dao.DictDao;
import com.gxa.dbutils.JdbcBuild;
import com.gxa.pojo.Dict;

import java.sql.SQLException;
import java.util.List;

public class DictDaoImpl extends JdbcBuild implements DictDao {
    @Override
    public List<Dict> queryDict(Integer param01, Integer param02) throws SQLException {
        String sql = "select * from dict limit ?,?";
        Object[] params = {param01,param02};
        List<Dict> list = super.queryListEntity(Dict.class, sql, params);
        return list;
    }

    @Override
    public Integer countDict() throws SQLException {
        String sql = "select count(*) from dict";
        int result = super.findAllForInt(sql, null);
        return result;
    }

    @Override
    public int add(Dict dict, String date) throws SQLException {
        String sql = "insert into dict(dict_num,dict_name,dict_value,remark,dict_time) values(?,?,?,?,?)";
        Object[] params = {dict.getDict_num(),dict.getDict_name(),dict.getDict_value(),dict.getRemark(),date};
        int result = super.executeUpdate(sql, params);
        System.out.println(sql);
        return result;
    }

    @Override
    public int del(String id) throws SQLException {
        String sql = "delete from dict where id=?";
        Object[] params = {id};
        int result = super.executeUpdate(sql, params);
        return result;
    }

    @Override
    public int mod(Dict dict, String date) throws SQLException {
        String sql = "update dict set dict_name=?,dict_time=?,dict_num=?,dict_value=?,remark=?where id=?";
        Object[] params = {dict.getDict_name(),date,dict.getDict_num(),dict.getDict_value(),dict.getRemark(),dict.getId()};
        int result = super.executeUpdate(sql, params);
        return result;
    }

    @Override
    public List<Dict> searchDict(Integer param01, Integer param02, String dict_name) throws SQLException {
        String sql = "select * from dict where dict_name like '%"+dict_name+"%' limit ?,?";
        Object[] params = {param01,param02};
        List<Dict> list = super.queryListEntity(Dict.class, sql, params);
        return list;
    }

    @Override
    public Integer countDict(String dict_name) throws SQLException {
        String sql = "select count(*) from dict where dict_name like '%"+dict_name+"%'";

        int result = super.findAllForInt(sql, null);
        return result;
    }
}
